package com.xyy.yueshijia.topic.topicbean;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xyy.yueshijia.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/2/14.
 */

public class MapAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private ArrayList<MapBean> data;
    private Context context;
    private LayoutInflater inflater;

    public MapAdapter( Context context,ArrayList<MapBean> data) {
        this.data = data;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.map_item, parent, false);
        return new MapHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof MapHolder){
            MapHolder mapholder= (MapHolder) holder;
            MapBean mapBean = data.get(position);
            mapholder.mapTitle.setText(mapBean.getArticle_title());
            mapholder.mapSubtitle.setText(mapBean.getArticle_abstract());

            String article_image = mapBean.getArticle_image();
            Glide.with(context).load(article_image)
                    .placeholder(R.drawable.ic_not_logged)
                    .error(R.drawable.ic_not_logged)
                    .into(mapholder.mapImage);
        }
    }

    @Override
    public int getItemCount() {
        return data != null ? data.size() : 0;
    }

    class MapHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.map_title)
        TextView mapTitle;
        @BindView(R.id.map_subtitle)
        TextView mapSubtitle;
        @BindView(R.id.map_image)
        ImageView mapImage;
        public MapHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
